﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TasksModel
{
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://mp.tasks.com/2010/")]
    public class TaskStatusList : TaskObservableCollection<TaskStatus>
    {
        public TaskStatusList Sort<TKey>(Func<TaskStatus, TKey> keySelector)
        {
            IOrderedEnumerable<TaskStatus> o = this.OrderBy(keySelector);
            int i = 0;
            SuspendChangedEvents();
            foreach (TaskStatus s in o)
            {
                Move(IndexOf(s), i);
                i++;
            }
            ResumeChangedEvents();
            return this;
        }

        public void SetupDefault()
        {
            Clear();
            Add(new TaskStatus(IdentifiedObject.GetAutoStaticGuid(1, 1))
            {
                Name = "Not Started",
                IsInitialStatus = true
            });
            Add(new TaskStatus(IdentifiedObject.GetAutoStaticGuid(1, 2))
            {
                Name = "In Progress"
            });
            Add(new TaskStatus(IdentifiedObject.GetAutoStaticGuid(1, 3))
            {
                Name = "Waiting for something"
            });
            Add(new TaskStatus(IdentifiedObject.GetAutoStaticGuid(1, 4))
            {
                Name = "Deferred"
            });
            Add(new TaskStatus(IdentifiedObject.GetAutoStaticGuid(1, 5))
            {
                Name = "Tentative"
            });
            Add(new TaskStatus(IdentifiedObject.GetAutoStaticGuid(1, 6))
            {
                Name = "Completed",
                IsFinalStatus = true
            });
        }
    }
}